import http from '@/utils/request'

// 获取商品分类列表（分页）
function getProductCategoryListReq(per = 1, page = 10) {
  return http({
    method: 'post',
    url: '/api/v1/admin/productcategory',
    params: { per, page },
  })
}

// 获取商品列表--名字（分页）
function getProductCategoryListToNameReq(per = 1, page = 10, name) {
  return http({
    method: 'post',
    url: '/api/v1/admin/product',
    params: { per, page, name },
  })
}
// 新增商品分类
function addProductCategoryReq(name, coverImage, desc, parent = 0) {
  return http({
    method: 'post',
    url: '/api/v1/admin/productcategory',
    data: { name, coverImage, desc, parent },
  })
}

// 修改商品分类
function modifyProductCategoryReq(id, name, coverImage, desc, parent = 0) {
  return http({
    method: 'put',
    url: '/api/v1/admin/productcategory/',
    data: { name, coverImage, desc, parent },
  })
}

// 删除商品分类
function delProductCategoryReq(id) {
  return http({
    method: 'delete',
    url: '/api/v1/admin/productcategory/' + id,
  })
}

// 获取商品列表（分页）
function getProductListReq( page = 1,per = 10) {
  return http({
    method: 'get',
    url: '/api/v1/admin/product',
    params: { per, page },
  })
}

// 新增商品
function addProductReq(
  name,
  coverImage,
  desc,
  content,
  views = 0,
  price,
  category,
  onSale = true,
  amount = 10,
) {
  return http({
    method: 'post',
    url: '/api/v1/admin/product',
    data: { name, coverImage, desc, content, views, price, category, onSale, amount },
  })
}

// 修改商品
function modifyProductReq(
  id,
  name,
  coverImage,
  desc,
  content,
  price,
  category,
  amount = 10,
  views = 0,
  onSale = true,
) {

  return http({
    method: 'put',
    url: '/api/v1/admin/product/' + id,
    data: { name, coverImage, desc, content,  price, category,amount, onSale, views },
  })
}

// 删除商品
function delProductReq(id) {
  return http({
    method: 'delete',
    url: '/api/v1/admin/product/' + id,
  })
}

// 获取商品评论列表（分页） product  商品id
function gelProductCommentListReq(per = 1, page = 10, product) {
  return http({
    method: 'post',
    url: '/api/v1/admin/productcomment',
    params: { per, page, product },
  })
}

// 删除商品评论
function delProductCommentReq(id) {
  return http({
    method: 'delete',
    url: '/api/v1/admin/productcomment' + id,
  })
}

// 订单管理列表
function getOrderListReq(per = 1, page = 10) {
  return http({
    method: 'post',
    url: '/api/v1/admin/order',
    params: { per, page },
  })
}

// 订单详情查询
function getOrderDetailReq(id) {
  return http({
    method: 'get',
    url: '/api/v1/admin/orderdetail',
    params: { id },
  })
}

export {
  getProductCategoryListReq,
  getProductCategoryListToNameReq,
  addProductCategoryReq,
  modifyProductCategoryReq,
  delProductCategoryReq,
  getProductListReq,
  addProductReq,
  modifyProductReq,
  delProductReq,
  gelProductCommentListReq,
  delProductCommentReq,
  getOrderListReq,
  getOrderDetailReq,
}
